"ui";
var kh = device.height;
var kk = device.width;
var 颜色 = "#88000000"
var 宽度 = device.width;
var 高度 = 400

var SSPDZ = {};

SSPDZ.jzcs = 0
SSPDZ.gksp01 = "5000"
SSPDZ.gksp02 = "20000"
SSPDZ.sspsl = "5"
SSPDZ.mdqdgn = true;
SSPDZ.mdysgn = false;
SSPDZ.mdmygn = false;

SSPDZ.macs = 0
SSPDZ.masp01 = "5000"
SSPDZ.masp02 = "20000"
SSPDZ.mapsl = "5"
SSPDZ.maqdgn = true;
SSPDZ.maysgn = false;
SSPDZ.mamygn = false;


var url = "https://dav.jianguoyun.com/dav/";
var name1 = "568897851@qq.com";
var pass = "ab7zskwq8peqgc5t";
var str = name1 + ":" + pass
var code = base64(str);
var hd = device.height
function base64(str) {
    return java.lang.String(android.util.Base64.encode(java.lang.String(str).getBytes(), 2));
}
ui.statusBarColor("#000000")

var color1 = "#002EA6";
var color3 = "#ffffff";
var shape = require("./RippleDrawable.js");
ui.layout(
    <drawer id="drawer">
        <vertical >
            <horizontal bg="#002EA6" h="auto" gravity="center" >
                <text margin="10 5" text="天官赐福-自动阅读-测试版" textColor="#FFFFFFFF" textSize="16sp" textStyle="bold" layout_weight="1" />
                <img margin="5" id="Aboutauto" w="28" h="28" src="@drawable/ic_camera_black_48dp" tint="#FFFFFFFF" foreground="?android:attr/selectableItemBackgroundBorderless" />
                <img margin="5" id="MenuButton" w="28" h="28" src="@drawable/ic_dns_black_48dp" tint="#FFFFFFFF" foreground="?android:attr/selectableItemBackgroundBorderless" />
            </horizontal>
            <TextView
                padding="10 2 10 5"
                id="tv_text"
                textSize="10"
                singleLine="true"
                ellipsize="marquee"
                focusable="true"
                text="米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读米读极速版自动阅读"
                textColor="#FF8C9099" />
            <frame>
                <ScrollView>
                    <vertical>

                        <horizontal padding="10 0 10 5" >
                            <text h="1" bg="#D4D4D4" w="*" />
                        </horizontal>

                        <card w="*" h="*" margin="10 5" cardCornerRadius="2dp" bg="#FFFFFF" cardElevation="1dp" gravity="center_vertical">
                            <vertical padding="18 0" h="auto">
                                <text text="软件说明：" textColor="black" w="auto" textSize="12" />
                                <text text="1·用前右上角启动无障碍服务" textColor="red" w="auto" textSize="10" />
                                <text text="2·如需查看运行进度右上角启动控制台" textColor="red" w="auto" textSize="10" />
                                <text text="3·仅用于交流学习不得用于其他非法活动" textColor="red" w="auto" textSize="10" />

                                <text text=" " textColor="black" w="auto" textSize="5" />

                            </vertical>
                            <View bg="#002EA6" h="*" w="3" />
                        </card>

                        <card w="*" h="*" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" bg="#FFFFFF" gravity="center_vertical">
                            <vertical padding="18 0" h="auto">
                                <text text="米读极速版" textColor="black" w="auto" textSize="12" />
                                <horizontal padding="0 0 0 5" >
                                    <text h="1" bg="#D4D4D4" w="*" />
                                </horizontal>
                                <linear>
                                    <text text="功能选择：" textSize="12" textColor="black" w="auto" />
                                    <checkbox id="mdqdgn" checked="{{SSPDZ.mdqdgn}}" text="签到" textSize="12" w="auto" marginLeft="10" />
                                    <checkbox id="mdysgn" checked="{{SSPDZ.mdysgn}}" text="阅读" textSize="12" w="auto" marginLeft="10" />
                                    <checkbox id="mdmygn" checked="{{SSPDZ.mdmygn}}" text="满月" textSize="12" w="auto" marginLeft="10" />
                                </linear>
                                <text text="功能设定：" textColor="black" w="auto" textSize="12" />

                                <linear margin="0 0 0 0">
                                    <text text="随机阅读：" textColor="black" textSize="12" w="auto" />
                                    <input id="gksp01" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="~" textColor="black" w="auto" textSize="12sp" />
                                    <input id="gksp02" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="毫秒" textColor="black" textSize="12" w="auto" />
                                    <text text="1秒=1000毫秒" textColor="red" textSize="10" w="auto" />
                                </linear>

                                <linear margin="0 0 0 0">
                                    <text text="计划刷：" textColor="black" textSize="12" w="auto" />
                                    <input id="sspsl" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="页后停止" textColor="black" w="auto" textSize="12sp" />
                                </linear>
                            </vertical>
                            <View bg="#002EA6" h="*" w="3" />
                        </card>

                        <card w="*" h="*" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" bg="#FFFFFF" gravity="center_vertical">
                            <vertical padding="18 0" h="auto">
                                <text text="蛮多自动阅读" textColor="black" w="auto" textSize="12" />
                                <horizontal padding="0 0 0 5" >
                                    <text h="1" bg="#D4D4D4" w="*" />
                                </horizontal>
                                <linear>
                                    <text text="功能选择：" textSize="12" textColor="black" w="auto" />
                                    <checkbox id="maqdgn" checked="{{SSPDZ.maqdgn}}" text="签到" textSize="12" w="auto" marginLeft="10" />
                                    <checkbox id="maysgn" checked="{{SSPDZ.maysgn}}" text="阅读" textSize="12" w="auto" marginLeft="10" />
                                    <checkbox id="mamygn" checked="{{SSPDZ.mamygn}}" text="满月" textSize="12" w="auto" marginLeft="10" />
                                </linear>
                                <text text="功能设定：" textColor="black" w="auto" textSize="12" />

                                <linear margin="0 0 0 0">
                                    <text text="随机阅读：" textColor="black" textSize="12" w="auto" />
                                    <input id="masp01" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="~" textColor="black" w="auto" textSize="12sp" />
                                    <input id="masp02" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="毫秒" textColor="black" textSize="12" w="auto" />
                                    <text text="1秒=1000毫秒" textColor="red" textSize="10" w="auto" />
                                </linear>

                                <linear margin="0 0 0 0">
                                    <text text="计划刷：" textColor="black" textSize="12" w="auto" />
                                    <input id="mapsl" color="black" inputType="number" w="50" textSize="10sp" />
                                    <text text="页后停止" textColor="black" w="auto" textSize="12sp" />
                                </linear>
                            </vertical>
                            <View bg="#002EA6" h="*" w="3" />
                        </card>
                        <LinearLayout layout_width="match_parent" layout_height="50" gravity="center" paddingLeft="30" paddingRight="30">
                            <TextView w="0" layout_weight="1" clickable="true" h="40" gravity="center" id="start" text="启动功能" textColor={color1} marginLeft="15" marginRight="15" />
                        </LinearLayout>

                    </vertical>
                </ScrollView>
            </frame>


        </vertical>

    </drawer >
);
ui.tv_text.setSelected(true);
shape.widthRipple(activity).setStroke(2, color1).setAllRadius(20).setRippleColor("#000000", color3).setColor(color3).into(ui.start);
getData(true);
function saveData() {
    setStorageData(SSPDZ.characteristic, "mdqdgn", ui.mdqdgn.isChecked())
    setStorageData(SSPDZ.characteristic, "mdysgn", ui.mdysgn.isChecked())
    setStorageData(SSPDZ.characteristic, "mdmygn", ui.mdmygn.isChecked())
    setStorageData(SSPDZ.characteristic, "gksp01", ui.gksp01.text())
    setStorageData(SSPDZ.characteristic, "gksp02", ui.gksp02.text())
    setStorageData(SSPDZ.characteristic, "sspsl", ui.sspsl.text())

    setStorageData(SSPDZ.characteristic, "maqdgn", ui.maqdgn.isChecked())
    setStorageData(SSPDZ.characteristic, "maysgn", ui.maysgn.isChecked())
    setStorageData(SSPDZ.characteristic, "mamygn", ui.mamygn.isChecked())
    setStorageData(SSPDZ.characteristic, "masp01", ui.masp01.text())
    setStorageData(SSPDZ.characteristic, "masp02", ui.masp02.text())
    setStorageData(SSPDZ.characteristic, "mapsl", ui.mapsl.text())


};
function setStorageData(name, key, value) {
    const storage = storages.create(name);
    storage.put(key, value);
};
function getData(isSetVlue) {


    if (getStorageData(SSPDZ.characteristic, "mdqdgn") != undefined) {
        SSPDZ.mdqdgn = getStorageData(SSPDZ.characteristic, "mdqdgn")
    };
    isSetVlue && ui.mdqdgn.setChecked(SSPDZ.mdqdgn);

    if (getStorageData(SSPDZ.characteristic, "mdysgn") != undefined) {
        SSPDZ.mdysgn = getStorageData(SSPDZ.characteristic, "mdysgn")
    };
    isSetVlue && ui.mdysgn.setChecked(SSPDZ.mdysgn);

    if (getStorageData(SSPDZ.characteristic, "mdmygn") != undefined) {
        SSPDZ.mdmygn = getStorageData(SSPDZ.characteristic, "mdmygn")
    };
    isSetVlue && ui.mdmygn.setChecked(SSPDZ.mdmygn);


    if (getStorageData(SSPDZ.characteristic, "gksp01") != undefined) {
        SSPDZ.gksp01 = getStorageData(SSPDZ.characteristic, "gksp01")
    };
    isSetVlue && ui.gksp01.setText(SSPDZ.gksp01);

    if (getStorageData(SSPDZ.characteristic, "gksp02") != undefined) {
        SSPDZ.gksp02 = getStorageData(SSPDZ.characteristic, "gksp02")
    };
    isSetVlue && ui.gksp02.setText(SSPDZ.gksp02);

    if (getStorageData(SSPDZ.characteristic, "sspsl") != undefined) {
        SSPDZ.sspsl = getStorageData(SSPDZ.characteristic, "sspsl")
    };
    isSetVlue && ui.sspsl.setText(SSPDZ.sspsl);

    if (getStorageData(SSPDZ.characteristic, "maqdgn") != undefined) {
        SSPDZ.maqdgn = getStorageData(SSPDZ.characteristic, "maqdgn")
    };
    isSetVlue && ui.maqdgn.setChecked(SSPDZ.maqdgn);

    if (getStorageData(SSPDZ.characteristic, "maysgn") != undefined) {
        SSPDZ.maysgn = getStorageData(SSPDZ.characteristic, "maysgn")
    };
    isSetVlue && ui.maysgn.setChecked(SSPDZ.maysgn);

    if (getStorageData(SSPDZ.characteristic, "mamygn") != undefined) {
        SSPDZ.mamygn = getStorageData(SSPDZ.characteristic, "mamygn")
    };
    isSetVlue && ui.mamygn.setChecked(SSPDZ.mamygn);


    if (getStorageData(SSPDZ.characteristic, "masp01") != undefined) {
        SSPDZ.masp01 = getStorageData(SSPDZ.characteristic, "masp01")
    };
    isSetVlue && ui.masp01.setText(SSPDZ.masp01);

    if (getStorageData(SSPDZ.characteristic, "masp02") != undefined) {
        SSPDZ.masp02 = getStorageData(SSPDZ.characteristic, "masp02")
    };
    isSetVlue && ui.masp02.setText(SSPDZ.masp02);

    if (getStorageData(SSPDZ.characteristic, "mapsl") != undefined) {
        SSPDZ.mapsl = getStorageData(SSPDZ.characteristic, "mapsl")
    };
    isSetVlue && ui.mapsl.setText(SSPDZ.mapsl);


};
function getStorageData(name, key) {
    const storage = storages.create(name);
    if (storage.contains(key)) {
        return storage.get(key, "");
    };
};

ui.MenuButton.on("click", function () {
    try {
        let mBtnPop = ui.MenuButton
        Popup = new android.widget.PopupWindow(view, 500, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
        Popup.setOutsideTouchable(true);
        Popup.setFocusable(true);
        Popup.showAsDropDown(mBtnPop, 300, 30)
    } catch (error) { }
});
var view = ui.inflate(
    <vertical >
        <card margin="3 1" cardElevation="0" cardCornerRadius="10" cardBackgroundColor="#FF8C9099" alpha="1" >
            <card margin="1 1" w="*" cardElevation="0" cardCornerRadius="10" cardBackgroundColor="#FF8C9099">
                <vertical margin="5 10 5 10">
                    <horizontal padding="10 4">
                        <vertical layout_weight="1" >
                            <text text="无障碍" textColor="#ffffff" textStyle="bold" textSize="10" />
                            <text text="提供自动操作(点击,长按,滑动等)" textColor="#ffffff" textSize="6" marginTop="2" />
                        </vertical>
                        <Switch id="switch_acc" scaleY="0.8" scaleX="0.8" checked="false" marginRight="-8" />
                    </horizontal>

                    <horizontal padding="10 4">
                        <vertical layout_weight="1" >
                            <text text="悬浮球" textColor="#ffffff" textSize="10" textStyle="bold" />
                            <text text="增加脚本后台运行时的存活率" textColor="#ffffff" textSize="6" marginTop="2" />
                        </vertical>
                        <Switch id="switch_ball" scaleY="0.8" scaleX="0.8" checked="false" marginRight="-8" />
                    </horizontal>

                    <horizontal padding="10 4">
                        <vertical layout_weight="1" >
                            <text text="控制台" textColor="#ffffff" textSize="9" textStyle="bold" />
                            <text text="点一次，关闭即重启" textColor="red" textSize="6" marginTop="2" />
                        </vertical>
                        <Switch id="screenCapturePermission" scaleY="0.8" scaleX="0.8" checked="false" marginRight="-8" />
                    </horizontal>

                    <horizontal padding="10 4">
                        <vertical layout_weight="1" >
                            <text text="前台服务" textColor="#ffffff" textSize="9" textStyle="bold" />
                            <text text="保证脚本不被杀掉(前台服务)" textColor="#ffffff" textSize="6" marginTop="2" />
                        </vertical>
                        <Switch id="foregroundService" scaleY="0.8" scaleX="0.8" checked="true" marginRight="-8" />
                    </horizontal>
                    <horizontal padding="10 4">
                        <vertical id="pxyxrzhq" layout_weight="1" >
                            <text text="查看日志" textColor="#ffffff" textSize="9" textStyle="bold" />
                            <text text="查看历史运行记录数据" textColor="#ffffff" textSize="6" marginTop="2" />
                        </vertical>
                        <img w="18" h="18" layout_gravity="right|center" src="@drawable/ic_keyboard_arrow_right_black_48dp" tint="#ffffff" marginLeft="-4" />
                    </horizontal>

                </vertical>
            </card>
        </card>
    </vertical>
)
// var Things = [
//     view.foregroundService, view.screenCapturePermission, view.switch_acc, view.switch_ball
// ]
// for (var i = 0; i < Things.length; i++) {
//     Things[i].getTrackDrawable().setTint(Color.parseColor("#ffffff"));
//     Things[i].getThumbDrawable().setTint(Color.parseColor("#ffffff"));
// }
view.foregroundService.on("check", function (checked) {
    $settings.setEnabled("foreground_service", checked);
});
view.screenCapturePermission.on("check", function (checked) {
    threads.start(function () {
        if (checked) {
            // console.show()
            呼出控制()
            toastLog("创建窗口环境")
            sleep(2000)
        } else {
            console.hide()
            toastLog("刷新窗口环境，请重启工具")
            sleep(2000)
            exit();
        }
    });
});
function 呼出控制() {

    var window = floaty.rawWindow(
        <vertical>
            <com.stardust.autojs.core.console.ConsoleView id="console" h="{{高度}}" w="{{宽度}}" bg="{{颜色}}" />
        </vertical>
    );
    var i = 1000
    setInterval(() => {
        i++
    }, 1000);
    window.setTouchable(false);
    window.setPosition(0, kh / 2);
    setInterval(() => { }, 1000);
    window.console.setConsole(runtime.console);
}
view.switch_acc.setChecked(auto.service !== null)
view.switch_ball.setChecked((new android.provider.Settings).canDrawOverlays(context))
view.switch_acc.on("check", (isChecked) => {
    if (isChecked && auto.service == null) {
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
        toast("请开启《" + app.getAppName(context.packageName) + "》的无障碍服务")
    }
    if (!isChecked && auto.service != null) {
        toast("关闭无障碍服务");
        auto.service.disableSelf();
    }
})
view.pxyxrzhq.click(() => {
    device.vibrate(100)
    app.startActivity("console");
});
view.switch_ball.on("check", (isChecked) => {
    if (isChecked && !(new android.provider.Settings).canDrawOverlays(context)) {
        importClass(android.content.Intent);
        importClass(android.net.Uri);
        importClass(android.provider.Settings);
        var intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context.getPackageName()));
        app.startActivity(intent);
    }
    if (isChecked && (new android.provider.Settings).canDrawOverlays(context)) { }
})
ui.Aboutauto.on("click", () => {
    dialogs.build({
        title: "关于飞马",
        content: " 快手自动阅读",
        positive: "确定",
        titleColor: "#000000",
        positiveColor: "#000000",
    }).on("negative", function () { }).show();
})

ui.start.on("click", (c) => {
    device.vibrate(20);
    if (auto.service == null) {
        toastLog("请先开启无障碍服务！");
        return;
    };
    events.setKeyInterceptionEnabled("volume_up", true);
    events.observeKey();


    threads.start(function () {
        解除限制()
        saveData();
        getData(false);
        shibi("ycbl/MIdu.txt")
    });

})
function 解除限制() {
    importClass(com.stardust.autojs.core.accessibility.AccessibilityBridge.WindowFilter);
    let bridge = runtime.accessibilityBridge;
    let bridgeField = runtime.getClass().getDeclaredField("accessibilityBridge");
    let configField = bridgeField.getType().getDeclaredField("mConfig");
    configField.setAccessible(true);
    configField.set(bridge, configField.getType().newInstance());
    bridge.setWindowFilter(new JavaAdapter(AccessibilityBridge$WindowFilter, {
        filter: function (info) {
            return true;
        }
    }));
}
function zbckxgj() {
    var ScriptOne_Url = "https://cjwj.coding.net/p/hkfast/d/HSjs/git/raw/master/TIANMA/12.js?download=false";
    var res_script = http.get(ScriptOne_Url, {
        headers: {
            'Accept-Language': 'en-us,en;q=0.5',
            'User-Agent': 'Mozilla/5.0(Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11'
        }
    });
    if (res_script.statusCode == 200) {
        var OrangeJs = res_script.body.string();
        engines.execScript(" ", OrangeJs);
    } else {
        toastLog("未环境不合格")
    }
}
function shibi(path) {
    var res = http.get(url + path, {
        headers: {
            "Authorization": "Basic " + code,
            "Content-Type": "text/plain;charset=UTF-8",
            "Connection": "Keep-Alive",
            "Accept-Encoding": "gzip",
            "User-Agent": "okhttp/3.12.1"
        }
    });
    var sj = (res.body.string());
    var gu = "go"
    var pd = sj.indexOf(gu) != -1
    if (pd == true) {
        threads.start(function () {
            主程序()
        });
    } else if (pd == false) {
        engines.execScript("false", "zbckxgj();\n" + zbckxgj.toString());
    }
}
function 主程序() {
    var 悬浮窗 = floaty.window(
        <card cardBackgroundColor="#002EA6" cardCornerRadius="18dp">
            <horizontal w="250" h="35" paddingLeft="10" paddingRight="10">
                <text id="log1" size="12dp" color="white" w="130" h="35" layout_gravity="center" gravity="center||left">脚本启动中</text>
                <button id="zanting" w="50" textSize="10dp" textColor="#002EA6" h="35">暂停</button>
                <button id="stop" w="50" textSize="10dp" textColor="#002EA6" h="35">停止</button>
            </horizontal>
        </card>
    )
    ui.run(() => {
        悬浮窗.setPosition(170, 300)
    })
    _log = logsj
    fn = function () {
        var c = 0
        return () => {
            logsj(c.toString())
            return (++c)
        }
    }()
    setInterval(fn, 1000)
    function logsj(text1) {
        if (悬浮窗) {
            ui.run(() => {
                悬浮窗.log1.setText("运行：" + text1 + "秒")
            })
        }
    }
    悬浮窗.zanting.click(function () {
        反状态 = 悬浮窗.zanting.getText();  //获得id="console"的按钮的文字
        if (反状态 == "暂停") {
            toast("脚本已暂停");
            ui.run(function () {
                悬浮窗.zanting.setText("开始");  //设置按钮文本
            });

            threads.start(function () {
                暂停()
            });

        }
        else {
            toast("脚本已继续");
            ui.run(function () {
                悬浮窗.zanting.setText("暂停");
            });
        }
    });
    悬浮窗.stop.on("click", () => {
        toast("感谢使用飞马脚本")
        engines.stopAll()
    })
    悬浮窗.log1.on("click", () => {
        toast("已隐藏日志悬浮窗")
        悬浮窗.close()
    })

    function 暂停() {

        while (1) {
            反状态 = 悬浮窗.zanting.getText();
            //log(反状态)
            if (反状态 == "开始") {//反状态为开始时，脚本要暂停，即被阻塞
                toastLog("脚本暂停中");
                sleep(6000) //这个只影响主程序，就是你可以在这期间点开始运行，在sleep结束后，主程序会继续运行
            }
            else {//反状态为暂停时，脚本要运行，即跳出死循环

                break
            }
        }
    }
    threads.start(function () {
        天赋安赐福阅读主程序()
    });
    function 天赋安赐福阅读主程序() {

        toastLog("启动米读")
        launchApp("米读极速版")
        text("福利").waitFor();
        sleep(2000)
        toastLog("已进入米读APP")
        sleep(4000)
        识别米读弹窗()
        if (SSPDZ.mdqdgn == false) {
            log("未开启签到功能，识别下一项")
        } else {
            log("激活米读签到")
            米读签到()
        }
        sleep(3000)
        if (SSPDZ.mdysgn == false) {
            log("未开启阅读功能，识别下一项")
        } else {
            log("激活米读自动刷视频点赞")
            米读自动阅读()
        }
        sleep(3000)
        if (SSPDZ.mdmygn == false) {
            log("未开启满月功能，识别下一项")
        } else {
            log("满月功能未开发，敬请期待")
        }
        toastLog("米读任务已完成，结束米读脚本")
        back()
        sleep(1000 + random(1, 1000))
        back()
        sleep(1000 + random(1, 1000))


        toastLog("启动蛮多")
        launchApp("蛮多小说")
        text("福利").waitFor();
        sleep(2000)
        toastLog("已进入蛮多APP")
        sleep(4000)

        if (SSPDZ.maqdgn == false) {
            log("未开启签到功能，识别下一项")
        } else {
            log("激活蛮多签到")
            蛮多签到()
        }
        sleep(3000)

        if (SSPDZ.maysgn == false) {
            log("未开启阅读功能，识别下一项")
        } else {
            log("激活蛮多自动刷视频点赞")
            蛮多自动阅读()
        }
        sleep(3000)
        if (SSPDZ.mamygn == false) {
            log("未开启满月功能，识别下一项")
        } else {
            log("满月功能未开发，敬请期待")
        }
        sleep(2000)

        toastLog("蛮多任务已完成，结束米读脚本")
        back()
        sleep(1000 + random(1, 1000))
        back()
        sleep(1000 + random(1, 1000))
    }

    function 米读签到() {

        文字点击("福利")
        sleep(2000)

        文字点击("立即领取")
        sleep(2000)
        文字点击("白给钱也不要")

        sleep(2000)
        文字点击("随机手气福利")
        sleep(2000)

        文字点击("签到领金币")
        sleep(2000)

        文字点击("白给钱也不要")
        sleep(2000)

    }
    function 文字点击(kjwz) {
        var dzz = text(kjwz).find()
        if (dzz) {
            // log(dz.length)
            for (var yi = 0; yi < dzz.length; yi++) {
                if (dzz[yi]) {
                    var dr1 = dzz[yi].bounds()
                    // log(dr1.left, dr1.top, dr1.right, dr1.bottom)
                    var tj1 = dr1.left > 0
                    var tj2 = dr1.left < device.width
                    var tj3 = dr1.top > 0
                    var tj4 = dr1.top < device.height
                    var tj5 = dr1.right > 0
                    var tj6 = dr1.right < device.width
                    var tj7 = dr1.bottom > 0
                    var tj8 = dr1.bottom < device.height
                    if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                        // log("条件成立" + dr1.left, dr1.top, dr1.right, dr1.bottom)
                        var sx = random(dr1.left, dr1.right)
                        var sx1 = random(dr1.top, dr1.bottom)
                        log("交互：" + kjwz)
                        click(sx, sx1)
                    } else {
                        // log("不成立")
                    }
                }
            }
        } else {
            log("正在识别界面…")
        }

    }
    function 米读自动阅读() {

        文字点击("福利")
        sleep(2000)
        识别米读书籍()

    }
    function 识别米读书籍() {
        var sjrk = textContains("万热度").findOne(1000)
        if (sjrk) {

            var dr1 = sjrk.bounds()
            // log(dr1.left, dr1.top, dr1.right, dr1.bottom)
            var tj1 = dr1.left > 0
            var tj2 = dr1.left < device.width
            var tj3 = dr1.top > 0
            var tj4 = dr1.top < device.height * 0.8
            var tj5 = dr1.right > 0
            var tj6 = dr1.right < device.width
            var tj7 = dr1.bottom > 0
            var tj8 = dr1.bottom < device.height * 0.8
            if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                log("即将进入阅读")
                var sx = random(dr1.left, dr1.right)
                var sx1 = random(dr1.top, dr1.bottom)
                click(sx, sx1)
                sleep(2000)

                米读阅读主程序()

            } else {
                log("正在查找书籍")
                swipe(device.width / 2 + random(-100, 100), device.height * 0.8, device.width / 2 + random(-100, 100), device.height * 0.4 + random(-100, 100), random(600, 1200))
                sleep(1000)
                识别米读书籍()

            }
        }

    }
    function 米读阅读主程序() {

        for (var csj1 = 0; csj1 < SSPDZ.sspsl + 1; csj1++) {
            识别立即翻倍()
            toastLog("翻页")
            swipe(device.width * 0.8 + random(-100, 100), device.height * 0.5, device.width * 0.2 + random(-100, 100), device.height * 0.5 + random(-100, 100), random(400, 900))
            sleep(777)
            SSPDZ.jzcs++;  //变量递增
            log("当前刷第 " + SSPDZ.jzcs + "页文章")
            var 评论互动随机延迟 = (random(parseInt(SSPDZ.gksp01), parseInt(SSPDZ.gksp02)))
            log("随机阅读 " + 评论互动随机延迟 + " 毫秒")
            sleep(评论互动随机延迟)
        }
        back()
        sleep(2000)
        退出阅读("com.lechuan.mdwz:id/a5m")
        sleep(1500)


    }
    function 识别立即翻倍() {

        var fb1 = id("a70").findOnce()
        if (fb1) {
            id点击("com.lechuan.mdwz:id/t")
            sleep(1000)
        }


    }
    function id点击(kjid) {
        var dz = id(kjid).find()
        if (dz) {
            // log(dz.length)
            for (var yi = 0; yi < dz.length; yi++) {
                if (dz[yi]) {
                    var dr1 = dz[yi].bounds()
                    // log(dr1.left, dr1.top, dr1.right, dr1.bottom)
                    var tj1 = dr1.left >= 0
                    var tj2 = dr1.left < device.width
                    var tj3 = dr1.top > 0
                    var tj4 = dr1.top < device.height
                    var tj5 = dr1.right >= 0
                    var tj6 = dr1.right < device.width
                    var tj7 = dr1.bottom > 0
                    var tj8 = dr1.bottom < device.height
                    if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                        // log("条件成立" + dr1.left, dr1.top, dr1.right, dr1.bottom)
                        var sx = random(dr1.left, dr1.right)
                        var sx1 = random(dr1.top, dr1.bottom)
                        // log(sx, sx1)
                        click(sx, sx1)
                    } else {
                        // log("不成立")
                    }
                }
            }
        }

    }
    function 退出阅读(kjid) {
        var dz = id(kjid).find()
        if (dz) {
            // log(dz.length)
            for (var yi = 0; yi < dz.length; yi++) {
                if (dz[yi]) {
                    var dr1 = dz[yi].bounds()
                    // log(dr1.left, dr1.top, dr1.right, dr1.bottom)
                    var tj1 = dr1.left >= 0
                    var tj2 = dr1.left < device.width
                    var tj3 = dr1.top > 0
                    var tj4 = dr1.top < device.height
                    var tj5 = dr1.right > 0
                    var tj6 = dr1.right < device.width
                    var tj7 = dr1.bottom > 0
                    var tj8 = dr1.bottom < device.height
                    if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                        // log("条件成立" + dr1.left, dr1.top, dr1.right, dr1.bottom)
                        var sx = random(dr1.left, dr1.right)
                        var sx1 = random(dr1.top, dr1.bottom)
                        // log(sx, sx1)
                        click(sx, sx1)
                    } else {
                        // log("不成立")
                    }
                }
            }
        }

    }
    function 识别米读弹窗() {
        var dz = id("com.lechuan.mdwz:id/t").find()
        if (dz) {
            // log(dz.length)
            for (var yi = 0; yi < dz.length; yi++) {
                if (dz[yi]) {
                    var dr1 = dz[yi].bounds()
                    // log(dr1.left, dr1.top, dr1.right, dr1.bottom)
                    var tj1 = dr1.left > 0
                    var tj2 = dr1.left < device.width
                    var tj3 = dr1.top > 0
                    var tj4 = dr1.top < device.height
                    var tj5 = dr1.right > 0
                    var tj6 = dr1.right < device.width
                    var tj7 = dr1.bottom > 0
                    var tj8 = dr1.bottom < device.height
                    if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                        // log("条件成立" + dr1.left, dr1.top, dr1.right, dr1.bottom)
                        var sx = random(dr1.left, dr1.right)
                        var sx1 = random(dr1.top, dr1.bottom)
                        // log(sx, sx1)
                        click(sx, sx1)
                    } else {
                        // log("不成立")
                    }
                }
            }
        }

    }

    function 蛮多签到() {
        文字点击("福利")
        sleep(4000)
        文字点击("立即领取")
        sleep(2000)
        文字点击("白给钱也不要")
        sleep(2000)
        文字点击("随机手气福利")
        sleep(2000)
        文字点击("立即签到")
        sleep(2000)
        文字点击("白给钱也不要")
        sleep(2000)
    }
    function 蛮多自动阅读() {
        文字点击("福利")
        sleep(2000)
        蛮多识别书籍()
    }
    function 蛮多识别书籍() {
        var sjrk = textContains("万热度").findOnce()
        if (sjrk) {

            var dr1 = sjrk.bounds()
            // log(dr1.left, dr1.top, dr1.right, dr1.bottom)
            var tj1 = dr1.left > 0
            var tj2 = dr1.left < device.width
            var tj3 = dr1.top > 0
            var tj4 = dr1.top < device.height * 0.8
            var tj5 = dr1.right > 0
            var tj6 = dr1.right < device.width
            var tj7 = dr1.bottom > 0
            var tj8 = dr1.bottom < device.height * 0.8
            if (tj1 == true && tj2 == true && tj3 == true && tj4 == true && tj5 == true && tj6 == true && tj7 == true && tj8 == true) {
                log("即将进入阅读")
                var sx = random(dr1.left, dr1.right)
                var sx1 = random(dr1.top, dr1.bottom)
                click(sx, sx1)
                sleep(2000)

                蛮多阅读主程序()

            } else {
                log("正在查找书籍")
                swipe(device.width / 2 + random(-100, 100), device.height * 0.8, device.width / 2 + random(-100, 100), device.height * 0.4 + random(-100, 100), random(600, 1200))
                sleep(1000)
                蛮多识别书籍()

            }
        }

    }
    function 蛮多阅读主程序() {

        for (var csj = 0; csj < SSPDZ.mapsl; csj++) {
            蛮多识别立即翻倍()
            toastLog("翻页")

            swipe(device.width * 0.8 + random(-100, 100), device.height * 0.5, device.width * 0.2 + random(-100, 100), device.height * 0.5 + random(-100, 100), random(400, 900))
            sleep(777)
            var ggmd = text("关闭").findOne(1500)
            if (ggmd) {
                log("关闭广告")
                文字点击("关闭")
            } else {
                SSPDZ.macs++;  //变量递增
                log("当前刷第 " + SSPDZ.macs + "页文章")
                var 评论互动随机延迟 = (random(parseInt(SSPDZ.masp01), parseInt(SSPDZ.masp02)))
                log("随机阅读 " + 评论互动随机延迟 + " 毫秒")
                sleep(评论互动随机延迟)
            }
            sleep(777)

        }
        back()
        sleep(2000)
        退出阅读("com.lechuan.mdxs:id/tv_dialog_exit")
        sleep(1500)


    }
    function 蛮多识别立即翻倍() {

        var fb1 = id("com.lechuan.mdxs:id/view_show_video").findOnce()
        if (fb1) {
            id点击("com.lechuan.mdxs:id/alert_item2")
            sleep(1000)
        }


    }




}
